******************************
* Table 7: Heterogeneous treatment effects on cognition and test scores, by child attendance rate

************************
clear all
set trace off
set more off
clear
use Jehanabad_analytic_sample_cognition

global socio_cov_4_vari no_HHmembers years_schooling_father years_schooling_mother asset_index
global school_cov_4_vari total_enrollment class_size student_teacher_ratio


sort child_unique wave
gen att=total_attendance_2
replace att=total_attendance_2[_n+1] if wave==0

g post=wave
label var post "Post"  /* Post denotes endline survey */
g treat_post=treat*post
label var treat_post "Treat*post"
xtile child_att_tercile=att, nquantiles(3)


gen att_70=(att>0.7) if att!=.
gen att_80=(att>0.8) if att!=.
gen att_90=(att>0.9) if att!=.


**Panel A 
eststo clear
foreach var in block_design_norm digit_span_forward_norm digit_span_backward_norm progressive_matrices_norm day_and_night_norm Cognition_Score_pca_norm math_norm reading_norm{
xtset child_unique wave
eststo: xtreg `var' treat_post treat post $socio_cov_4_vari $school_cov_4_vari if att_70==1, fe cluster (school_id)
}
esttab using Table7_panel_A_70%.rtf, se(a3) keep(treat_post) varwidth(35) b(a3) star(* 0.10 ** 0.05 *** 0.01) replace ///
title(Table 7: Heterogeneous treatment effects on cognition and test scores, by child attendance rate)  mtitles("Block design" "Digit span forward" "Digit span backward" "Progressive matrices" ///
"Day and night" "Cognitive index" "Math test score" "Reading test score") /// 
coeflabels(treat_post "Treat*post (70% attendance)") nonotes label 


eststo clear
foreach var in block_design_norm digit_span_forward_norm digit_span_backward_norm progressive_matrices_norm day_and_night_norm Cognition_Score_pca_norm math_norm reading_norm{
xtset child_unique wave
eststo: xtreg `var' treat_post treat post $socio_cov_4_vari $school_cov_4_vari if att_80==1, fe cluster (school_id)
}
esttab using Table7_panel_A_70%.rtf, se(a3) keep(treat_post) varwidth(35) b(a3) star(* 0.10 ** 0.05 *** 0.01) append ///
mtitles("Block design" "Digit span forward" "Digit span backward" "Progressive matrices" ///
"Day and night" "Cognitive index" "Math test score" "Reading test score") /// 
 coeflabels(treat_post "Treat*post (80% attendance)") nonotes label

eststo clear
foreach var in block_design_norm digit_span_forward_norm digit_span_backward_norm progressive_matrices_norm day_and_night_norm Cognition_Score_pca_norm math_norm reading_norm{
xtset child_unique wave
eststo: xtreg `var' treat_post treat post $socio_cov_4_vari $school_cov_4_vari if att_90==1, fe cluster (school_id)
}
esttab using Table7_panel_A_70%.rtf, se(a3) keep(treat_post) varwidth(35) b(a3) star(* 0.10 ** 0.05 *** 0.01) append ///
mtitles("Block design" "Digit span forward" "Digit span backward" "Progressive matrices" ///
"Day and night" "Cognitive index" "Math test score" "Reading test score") /// 
 coeflabels(treat_post "Treat*post (90% attendance)") nonotes label




**********************************************************
**********************************************************
***Table 6, lets do child att by tercile instead of 70, 80, 90% cutoff
***********************************************************
**********************************************************

* Panel B, by child attendance terciles
eststo clear
foreach var in block_design_norm digit_span_forward_norm digit_span_backward_norm progressive_matrices_norm day_and_night_norm Cognition_Score_pca_norm math_norm reading_norm{
xtset child_unique wave
eststo: xtreg `var' treat_post treat post $socio_cov_4_vari $school_cov_4_vari if child_att_tercile==1, fe cluster (school_id)
}
esttab using Table7_panel_A_70%.rtf, se(a3) keep(treat_post) varwidth(35) b(a3) star(* 0.10 ** 0.05 *** 0.01) append ///
mtitles("Block design" "Digit span forward" "Digit span backward" "Progressive matrices" ///
"Day and night" "Cognitive index" "Math test score" "Reading test score") /// 
coeflabels(treat_post "Treat*post (Bottom tercile)") nonotes label 


eststo clear
foreach var in block_design_norm digit_span_forward_norm digit_span_backward_norm progressive_matrices_norm day_and_night_norm Cognition_Score_pca_norm math_norm reading_norm{
xtset child_unique wave
eststo: xtreg `var' treat_post treat post $socio_cov_4_vari $school_cov_4_vari if child_att_tercile==2, fe cluster (school_id)
}
esttab using Table7_panel_A_70%.rtf, se(a3) keep(treat_post) varwidth(35) b(a3) star(* 0.10 ** 0.05 *** 0.01) append ///
mtitles("Block design" "Digit span forward" "Digit span backward" "Progressive matrices" ///
"Day and night" "Cognitive index" "Math test score" "Reading test score") /// 
coeflabels(treat_post "Treat*post (Middle tercile)") nonotes label 

eststo clear
foreach var in block_design_norm digit_span_forward_norm digit_span_backward_norm progressive_matrices_norm day_and_night_norm Cognition_Score_pca_norm math_norm reading_norm{
xtset child_unique wave
eststo: xtreg `var' treat_post treat post $socio_cov_4_vari $school_cov_4_vari if child_att_tercile==3, fe cluster (school_id)
}
esttab using Table7_panel_A_70%.rtf, se(a3) keep(treat_post) varwidth(35) b(a3) star(* 0.10 ** 0.05 *** 0.01) append ///
mtitles("Block design" "Digit span forward" "Digit span backward" "Progressive matrices" ///
"Day and night" "Cognitive index" "Math test score" "Reading test score") /// 
coeflabels(treat_post "Treat*post (Top tercile)") nonotes label ///
addnotes("Notes: Each cell reports DD coefficients from a separate regression. Standard errors, clustered at the school" ///
"level, are reported in parentheses. All outcomes are normalized with reference to the baseline mean in the control group." ///
"All regressions include child fixed effects and time-variant household & school-level controls reported in Table 4." ///
" *, **, *** denote significance at the 10%, 5%, and 1% level, respectively.")


********************************************End of do file *******************


